﻿using System;
using Tao.OpenGl;

namespace Aeon.Framework.Objects
{

/// <summary>
/// Prism primitive class.
/// Uses up to 3 colors and textures, for top, bottom, and sides.
/// 
/// </summary>
public class Prism : ObjectBase
    {
    // --- Attributes:
    
    private Int32 detail;       // Prism level of detail. 
    private Single baseR;       // Prism base rad.
    private Single topR;        // Prism top rad.
    private Single size;        // Prism height.
    
    // --- Constructor:

    /// <summary>
    /// Cylinder constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="height"> Cylinder size. </param>
    /// <param name="rad"> Cylinder rad. </param>
    public Prism(String key, Position origin, Orientation angle, Single height, Single radius)
        : this(key,origin,angle,height,radius,radius,20,AeonMaterials.Default) { }

    /// <summary>
    /// Custom prism constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="baseRadius"> Prism base rad. </param>
    /// <param name="topRadius"> Prism top rad. </param>
    /// <param name="height"> Prism height. </param>
    /// <param name="lod"> Prism level of detail, in number of base sides. </param>
    /// <param name="material"> Object material. </param>
    public Prism(String key, Position origin, Orientation angle, Single height, Single baseRadius, Single topRadius, Int32 lod, AeonMaterial material)
        : base(key,origin,angle,material)
        {
        detail = lod;
        size = height;
        topR = topRadius;
        baseR = baseRadius;
        }
        
    // --- Public Methods:

    public override void Draw()
        {
        Gl.glTranslatef(origin.xPos,origin.yPos,origin.zPos);
        Gl.glRotatef(angle.xAng-90,1,0,0);
        Gl.glRotatef(angle.yAng,0,1,0);
        Gl.glRotatef(angle.zAng,0,0,1);
        
        Glu.GLUquadric quadric = Glu.gluNewQuadric();

        Glu.gluQuadricDrawStyle(quadric, Glu.GLU_FILL);
        Glu.gluQuadricNormals(quadric, Glu.GLU_SMOOTH);
        Glu.gluQuadricTexture(quadric,Gl.GL_TRUE);
        
        // Bottom:
        Gl.glColor4f(material.Color.R,material.Color.G,material.Color.B,material.Color.A);
        material.Texture.Bind();
        
        Glu.gluQuadricOrientation(quadric, Glu.GLU_INSIDE);
        Glu.gluDisk(quadric,0,baseR,detail,1);
        
        // Sides:
        Gl.glColor4f(material.Color.R,material.Color.G,material.Color.B,material.Color.A);
        material.Texture.Bind();
        
        Glu.gluQuadricOrientation(quadric, Glu.GLU_OUTSIDE);
        Glu.gluCylinder(quadric,baseR,topR,size,detail,detail);
        
        // Top:
        Gl.glColor4f(material.Color.R,material.Color.G,material.Color.B,material.Color.A);
        material.Texture.Bind();
        
        Gl.glTranslatef(0,0,size);
        Glu.gluDisk(quadric,0,topR,detail,1);
        
        Glu.gluDeleteQuadric(quadric);
        }

    }


}